<%
/**
 * multiSelect 外部调用的组织机构单选弹处对话框
 * 
 * @author   李荣华
 * @version v1.0
 * @date     2011-09-29
 * @since   JDK1.6
 */
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="at" uri="/WEB-INF/util_tag.tld"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><s:text name="organ.singleSelect.title"></s:text></title>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
	<meta content="no-cache" http-equiv="Pragma"/>
	<meta content="no-cache" http-equiv="Cache-Control"/>
	<meta content="0" http-equiv="Expires"/>
	<meta name="GENERATOR" content="MSHTML 8.00.6001.18854"/>
	<link rel="stylesheet" id="dialog" type="text/css" href="<at:url css="dialog.css"/>" />
	<link href="${rootPath}/Common/Js/zTree/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="${rootPath}/Common/Js/jquery.js"></script>
	<script type="text/javascript" src="<at:url js="dialog.js"/>"></script>
	<script type="text/javascript" src="${rootPath}/Common/Js/zTree/jquery.ztree.all-3.1.js"></script>
	<script type="text/javascript" src="${rootPath}/Common/Js/common.js"></script>
    <script type="text/JavaScript">
    
	    var MyObject = window.dialogArguments;
		
		//暂存选择节点数据
		function clickNode(id,name){	
			//alert(id+":"+name);	
		    document.getElementById("orgId").value=id;
		    document.getElementById("orgName").value=name;
		}
	    
	    function okClick() 
	    {
		    if ( document.getElementById("orgId").value != "" ) 
		    {
			    MyObject.id.value = document.getElementById("orgId").value;
			    MyObject.name.value = document.getElementById("orgName").value;
		    	if (MyObject.pWindow.getIntoHospital)
					MyObject.pWindow.getIntoHospital(document.getElementById("orgId").value);
			    window.close();
		    }
	        else
	        {  
	            alert('<s:text name="js.common.noChoise"></s:text>');
	        }
	    }
	    
	    function doCancel()
	    {
	        window.close();
	    }
	    
	    var zTree;
		var zNodes = eval('(' + '${topTree}' + ')');

		var setting = {
				data: {
					simpleData: {
						enable: true,
						idKey: "id",
						pIdKey: "pId"
					}
				},
				async: {
					enable: true,
					url: "${rootPath}/Base/Organ!getSubTree",
					autoParam: ["id"]
				},
				callback: {
					onClick: zTreeOnClick
				}
			};
		
		function refreshTree() {
			//zTree = $("#tree").zTree(setting, zNodes);
			$.fn.zTree.init($("#tree"), setting, zNodes);
			zTree = $.fn.zTree.getZTreeObj("tree");
		}
		
		function zTreeOnClick(event, treeId, treeNode) {
			document.getElementById("orgId").value=treeNode.id;
		    document.getElementById("orgName").value=treeNode.name;
		}
		
		function zTreeOnAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
			alert("eer");
		}
		
		$(document).ready(function(){
			refreshTree();	
		});
		
		//取机构数据
		function getTree(obj){
			var id=obj.options[obj.options.selectedIndex].value;
			$.getJSON("${rootPath}/Base/Organ!getTree?id="+id,function(data){
				zNodes = data;
				refreshTree();
			}); 
		}
    
    </script>
	<base target="_self"/>
</head>
<body>
<form action="">
	<input type="hidden" name="orgId" id="orgId" value=""/>
	<input type="hidden" name="orgName" id="orgName" value=""/>
	<div>
		<div>
	    	<div class="ele_tree_select_single" style="height: 21px">
	        	<select name="root" onchange="getTree(this);" style="width: 250px;height: 21px;">
					<s:iterator value="#request['unitList']">
						<option value="${id}">${name}</option>
					</s:iterator>
				</select>
	        </div>
	        <div class="ele_tree_con_single"><ul id="tree" class="ztree"></ul></div>
	    </div>
		<div class="clear_div"></div>
		<div class="dialog_button">
			<div class="button_left" onclick="okClick();">
				<s:text name="common.confirm"></s:text>
			</div>
			<div class="button_right" onclick="doCancel();">
				<s:text name="common.cancel"></s:text>
			</div>
		</div>
	</div>
</form>
</body>
</html>
